package cm.tl.pms.util.fileParser.excel;

import java.util.HashMap;
import java.util.Map;

public class CurrencyConverter {

    // 币种映射表
    private static final Map<String, String> CURRENCY_MAP = new HashMap<>();
    // 反向映射表
    private static final Map<String, String> REVERSE_CURRENCY_MAP = new HashMap<>();

    static {
        CURRENCY_MAP.put("CNY", "人民币");
        CURRENCY_MAP.put("USD", "美元");
        CURRENCY_MAP.put("EUR", "欧元");
        CURRENCY_MAP.put("JPY", "日元");
        CURRENCY_MAP.put("GBP", "英镑");
        CURRENCY_MAP.put("AUD", "澳大利亚元");
        CURRENCY_MAP.put("CAD", "加拿大元");
        CURRENCY_MAP.put("CHF", "瑞士法郎");
        CURRENCY_MAP.put("HKD", "港元");
        CURRENCY_MAP.put("SGD", "新加坡元");

        // 填充反向映射表
        for (Map.Entry<String, String> entry : CURRENCY_MAP.entrySet()) {
            REVERSE_CURRENCY_MAP.put(entry.getValue(), entry.getKey());
        }
    }

    /**
     * 将币种名称（英文缩写或中文名称）转换成中文名称
     *
     * @param currency 币种名称
     * @return 对应的中文名称
     */
    public static String convertToChinese(String currency) {
        if (currency == null || currency.isEmpty()) {
            return currency; // 为空直接返回
        }

        // 检查是否已经是中文名称
        if (REVERSE_CURRENCY_MAP.containsKey(currency)) {
            return currency; // 已经是中文名称，直接返回
        }

        // 将输入的币种缩写转换为大写
        String upperCaseCurrency = currency.toUpperCase();

        // 从映射表中获取对应的中文名称
        return CURRENCY_MAP.getOrDefault(upperCaseCurrency, "未知币种");
    }

    public static void main(String[] args) {
        // 测试示例
        String currency = "usd";
        String chineseCurrency = convertToChinese(currency);
        System.out.println("输入: " + currency + ", 输出: " + chineseCurrency);

        currency = "EUR";
        chineseCurrency = convertToChinese(currency);
        System.out.println("输入: " + currency + ", 输出: " + chineseCurrency);

        currency = "cny";
        chineseCurrency = convertToChinese(currency);
        System.out.println("输入: " + currency + ", 输出: " + chineseCurrency);

        currency = "人民币";
        chineseCurrency = convertToChinese(currency);
        System.out.println("输入: " + currency + ", 输出: " + chineseCurrency);

        currency = "未知币种";
        chineseCurrency = convertToChinese(currency);
        System.out.println("输入: " + currency + ", 输出: " + chineseCurrency);

        currency = ""; // 为空
        chineseCurrency = convertToChinese(currency);
        System.out.println("输入: " + currency + ", 输出: " + chineseCurrency);
    }
}
